<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />
    <title>区域基站修改</title>
    <link href="../../layui/css/layui.css" rel="stylesheet" type="text/css">
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <link href="../../layui/css/iconfont/iconfont.css" rel="stylesheet" type="text/css">
    <script src="../../layui/layui.js"></script>
    <script src="../../js/jquery-1.8.3.js"></script>
    <script src="../../js/util.js"></script>

    <!-- <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=nSGoPNzNrehEaGBst1TZzklH"></script> -->
    <!--加载鼠标绘制工具-->
    <!-- <script type="text/javascript" src="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.js"></script>
    <link rel="stylesheet" href="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.css" /> -->
    <!--加载检索信息窗口-->
    <!-- <script type="text/javascript" src="http://api.map.baidu.com/library/SearchInfoWindow/1.4/src/SearchInfoWindow_min.js"></script>
    <link rel="stylesheet" href="http://api.map.baidu.com/library/SearchInfoWindow/1.4/src/SearchInfoWindow_min.css" /> -->
    <!--测算工具类-->
    <!-- <script type="text/javascript" src="http://api.map.baidu.com/library/GeoUtils/1.2/src/GeoUtils_min.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/library/Heatmap/2.0/src/Heatmap_min.js"></script>
    <script src="http://mapv.baidu.com/build/mapv.min.js"></script> -->

    <!-- 自定义添加script -->
    <script type="text/javascript">
      !function addScript () {
        var pathObj = {
          scriptList: [
            "/api?v=2.0&ak=nSGoPNzNrehEaGBst1TZzklH",
            //加载鼠标绘制工具
            "/library/DrawingManager/1.4/src/DrawingManager_min.js",
            // -加载检索信息窗口
            "/library/SearchInfoWindow/1.4/src/SearchInfoWindow_min.js",
            //测算工具类
            "/library/GeoUtils/1.2/src/GeoUtils_min.js",
            "/library/Heatmap/2.0/src/Heatmap_min.js",
          ],
          scriptListTwo: [
            "/build/mapv.min.js"
          ],
          link: [
            "/library/SearchInfoWindow/1.4/src/SearchInfoWindow_min.css",
            "/library/DrawingManager/1.4/src/DrawingManager_min.css"
          ]
        }
        var urlArr = window.sessionStorage.getItem('urlStr').split(";");
        var oHead = document.getElementsByTagName('HEAD').item(0);
        pathObj.scriptList.forEach(element => {
          var oScript = document.createElement("script");
          oScript.type = "text/javascript";
          oScript.src = urlArr[0] + element;
          oHead.appendChild(oScript);
        });
        pathObj.scriptListTwo.forEach(element => {
          var oScript = document.createElement("script");
          oScript.type = "text/javascript";
          oScript.src = urlArr[1] + element;
          oHead.appendChild(oScript);
        });
        pathObj.link.forEach(element => {
          var oLink = document.createElement("link");
          oLink.type = "stylesheet";
          oLink.href = urlArr[0] + element;
          oHead.appendChild(oLink);
        });
      }();
    </script>

    <script src="../../js/jquery-ui-1.10.4.custom.min.js"></script>
    <style type="text/css">
        /*body, html,#allmap{*/
        /*    width: 100%;height: 1000px;overflow: hidden;margin:0;font-family:"微软雅黑";}*/

        #result {width:100%;font-size:12px;}

        ul,li{list-style: none;margin:0;padding:0;float:left;}
        .jistation .layui-form-switch{
            float:right ;
            margin-top:0;
            height:21px;
            width:38px;
        }
        .jistation .layui-form-onswitch{
            background: #007AFF;
            border-color:#007AFF;
        }

        .xianstation .input-text{
            display: inline-block;
            padding-left:0;
            width:74%;
            background:transparent;
            font-size:12px;
            height:30px;
            line-height: 30px;
            color:#8F8F8F;
            border-width: 0;
        }

        .tabar img{
            width:40px;
            height:40px;
        }

        .layui-form-checked[lay-skin=primary] i{
            background:#007AFF !important;
            border-color:#007AFF !important;
        }

        .formedit .layui-form-radio>i:hover,
        .formedit .layui-form-radioed>i {
            color: #007AFF;
            font-size:16px;
            margin-right:4px;
        }
        .formedit .layui-form-select{
            margin-right: 25px;
        }
        .formedit .layui-form-select dl dd.layui-this{
            background: #007AFF;
        }
        .formedit .layui-form-select .layui-input{
            padding:8px;
        }
        .formedit .layui-form-select dl{
            top:28px;
            padding:0;
        }
        .formedit .layui-form-select dl dd,
        .formedit .layui-form-select dl dt{
            line-height: 26px;
            font-size: 12px;
        }
        .formedit .layui-input,
        .formedit .layui-form-item .layui-input-inline{
            width:auto ;
        }
        .formedit .layui-form-radio{
            line-height:26px;
            margin:0;
        }
        .formedit .layui-form-radio>i{
            font-size:16px;
            margin-right:4px;
        }

        .formedit .layui-form-radio *{
            color:#8A8A8A;

        }
        .formedit .inputblock{
            margin-left:0;
            min-height:26px;
        }
        .formedit .layui-input, .layui-select{
            width:160px;
            height:26px;
            line-height: 26px;
            font-size:12px;
            color:#363636
        }
        .formedit .layui-form-switch{
            margin-top:0;
            width: 38px;
            height: 21px;
            line-height: 21px;
            padding:0;
        }
        .formedit .layui-form-onswitch{
            background: #007AFF;
            border-color:#007AFF;
        }
        .formedit .wth104{
            width:104px
        }
        .formedit .mat4{
            margin-top: 4px;
        }
        .formedit .fr{
            float:right
        }
        .formedit .btnsalign{
            text-align: center;
        }
        .formedit .layui-btn{
            width: 79px;
            height: 26px;
            background: #218EEB;
            line-height: 26px;
            border-radius: 13px;
            font-size:12px;
        }
        .formedit .disableinput{
            background:#f2f2f2;
        }
        .formedit .layui-tab{
            margin:0;
        }
        .formedit .layui-tab-brief .layui-tab-title{
            width:100%;
        }
        .formedit .layui-tab-brief>.layui-tab-title .layui-this{
            color:#007fff;
        }
        .formedit .layui-tab-brief>.layui-tab-more li.layui-this:after,
        .formedit .layui-tab-brief>.layui-tab-title .layui-this:after{
            border-bottom:2px solid #007fff;
        }
        .formedit .contentnone{
            font-size: 14px;
            color: #aeaeae;
            text-align: center;
            padding-top: 109px;
        }
        .formedit .textareas{
            margin-top: 44px;
            height: 195px;
            resize:none;
        }
        .formedit .step1heigth{
            height:252px;
            padding-top:18px;
        }
        .formedit .step2wid{
            height:270px;
        }
        .formedit .layui-tab-content{
            padding: 10px 0;
        }

    </style>
    <script type="text/javascript">
        $(function () {
            $('.tabars').css('height',document.body.clientHeight+'px') ;
            $('#test12').css({'height':document.body.clientHeight-294+'px','overflow-y':'auto'});
        })



        var map = null;
        var mapvLayer = null;
        var circleOverlays = [];
        var rectangleOverlays = [];
        var pointsOverlays = [];
        var latitudeAndLongitudeValueArr = [];
        var pointName = [];
        var mgrId = "";
        var linePointNames = [];
        var XuYiStations = [];
        var colorArray = ["#1F82EE","#7D7D7D","#E98E20","#1DD73A","#1CE5BF","#7D22E3","#E131BF","#EC1F1F"];
        layui.use(['tree','form', 'layer', 'jquery', 'element', 'upload', 'table'], function () {
            var table = layui.table;
            var form = layui.form;
            var $ = layui.$;
            var layer = layui.layer;
            var upload = layui.upload;
            var user;
            var mgrId = getUrlParam("mgrId");
            var cityId = getUrlParam("cityId");
            var importStationType="";//导入基站csv文件类型（追加or覆盖）
            var copyMgrId;
            var mgrNameId;//项目简称id


            var form = layui.form;
            var $ = layui.$;
            var util = layui.util;
            var layer = layui.layer;
            var tree = layui.tree;
            let treeData = [];
            var title='项目基本信息';

            for(var i=0;i<4;i++){
                $(".content").eq(i).hide();
            }
            $(".content").eq(0).show();
            $(".tabar").click(function(){
                for(var i=0;i<4;i++){
                    $(".content").eq(i).hide();
                    $(".tabar").eq(i).css("backgroundColor","#F9F9F9")
                }
                $(".content").eq($(".tabar").index(this)).show();
                $(this).css("backgroundColor","#fff")
            })
            //swtich的值
            form.on('switch(switchTest)', function (data) {
                console.log(data.elem); //得到checkbox原始DOM对象
                console.log(data.elem.checked); //开关是否开启，true或者false
                console.log(data.value); //开关value值，也可以通过data.elem.value得到
                console.log(data.othis); //得到美化后的DOM对象
                var x = data.elem.checked;
                console.log(x);
            });

            //搜索框的值
            $('#query').on('click', function () {
                var name = $("#inputs-name").val();
                console.log("name"+name);
                treeData = test(name);
                console.log(JSON.stringify(treeData));
                //重载实例
                tree.reload('demoId1', {
                    elem: '#test12' //默认是点击节点可进行收缩
                    ,data: treeData
                    ,edit:false
                    ,showCheckbox: true  //是否显示复选框
                    ,oncheck: function(obj){
                        console.log(obj.data); //得到当前点击的节点数据
                        console.log(obj.checked); //得到当前节点的展开状态：open、close、normal
                        console.log(obj.data.checked); //得到当前节点元素
                    }
                });
            });
            //swtich的值
            form.on('switch(showStation)', function (data) {
                if(XuYiStations.length ==0){
                    layer.msg("基站数据正在加载，请稍候再试");
                    data.elem.checked = false;
                    $("#showStation").removeClass("layui-form-onswitch");
                    layui.form.render();
                    return false;
                }

                console.log(data.elem); //得到checkbox原始DOM对象
                console.log(data.elem.checked); //开关是否开启，true或者false
                console.log(data.value); //开关value值，也可以通过data.elem.value得到
                console.log(data.othis); //得到美化后的DOM对象
                var x = data.elem.checked;
                if (mapvLayer!=null){
                    if (x){
                        mapvLayer.show();
                    } else {
                        mapvLayer.hide()
                    }
                }
            });

            // var initialFunc = function(){
            //     // 创建Map实例,设置地图允许的最小/大级别
            //     map = new BMap.Map("allmap",{enableMapClick:false});
            //     //开启滚轮缩放
            //     map.enableScrollWheelZoom(true);
            //     console.info("-----"+cityId);
            //     console.info("======"+getJWByCityId());
            //     map.centerAndZoom(getJWByCityId(cityId),11);
            //
            //     map.setMaxZoom(18);
            //     map.setMinZoom(11);
            //     //右下角添加控件
            //     map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT , type: BMAP_NAVIGATION_CONTROL_SMALL}));
            //     function ZoomControl(){
            //         // 默认停靠位置和偏移量
            //         this.defaultAnchor = BMAP_ANCHOR_TOP_RIGHT;
            //         this.defaultOffset = new BMap.Size(0, 80); // 距离左上角位置
            //     }
            //     ZoomControl.prototype = new BMap.Control();
            //
            //     // 自定义控件必须实现自己的initialize方法,并且将控件的DOM元素返回
            //     // 在本方法中创建个div元素作为控件的容器,并将其添加到地图容器中
            //     ZoomControl.prototype.initialize = function(map){
            //         // 创建一个DOM元素
            //         var div = document.createElement("div");
            //         // 添加文字说明
            //         div.appendChild(document.createTextNode("保存"));
            //         // 设置样式
            //         div.style.cursor = "pointer";
            //         div.style.border = "1px solid gray";
            //         div.style.backgroundColor = "white";
            //         div.style.width = "55px";
            //         div.style.height = "45px";
            //         div.style.textAlign='center';
            //         div.style.backgroundColor='#2e84b5';
            //         div.style.color='#ededed';
            //         div.style.lineHeight='45px';
            //         div.style.textAlign='center';
            //         div.style.borderRadius='10px';
            //         // 绑定事件
            //         div.onclick = function(e){
            //             if((circleOverlays.length+rectangleOverlays.length)===0 && pointName.length===0){
            //                 layer.open({
            //                     title:"提示"
            //                     ,type: 1
            //                     ,offset: 'auto'
            //                     ,id: 'layerDemo' //防止重复弹出
            //                     ,content: '<div style="padding: 20px 80px;"><span>请先选取发送区域或点位再进行保存</span></div>'
            //                     ,btn: '关闭'
            //                     ,btnAlign: 'c' //按钮居中
            //                     ,shade: 0 //不显示遮罩
            //                     ,yes: function(){
            //                         layer.closeAll();
            //                     }
            //                 });
            //             }else{
            //                 var txt=  "目前圈画"+(circleOverlays.length+rectangleOverlays.length)+"个区域，将保存发送范围，请确认！";
            //                 layer.open({
            //                     type: 1
            //                     ,offset: 'auto'
            //                     ,id: 'layerDemo' //防止重复弹出
            //                     ,content: '<div style="padding: 20px 80px;"><span>'+txt+'</span></div>'
            //                     ,btn: ['确定','取消']
            //                     ,yes: function(){
            //                         latitudeAndLongitudeValueArr.length=0;
            //                         for (let i =0;i<circleOverlays.length;i++){
            //                             latitudeAndLongitudeValueArr.push(circleOverlays[i].getCenter().lng+","+circleOverlays[i].getCenter().lat+"+"+circleOverlays[i].getRadius());
            //                         }
            //                         for (let i =0;i<rectangleOverlays.length;i++){
            //                             latitudeAndLongitudeValueArr.push(getPoints(rectangleOverlays[i]));
            //                         }
            //                         console.info(JSON.stringify(latitudeAndLongitudeValueArr));
            //                         var json;
            //                         let jsonParams ={
            //                             'mgrId': mgrId
            //                             ,'longAndLatListInfo' : JSON.stringify(latitudeAndLongitudeValueArr)
            //                         };
            //                         var url = '/sendRange/getStations';
            //                         $.ajax({
            //                             contentType:"application/json;charset=UTF-8",
            //                             type: 'post',
            //                             url: url,
            //                             data:JSON.stringify(jsonParams),
            //                             dataType:'json',
            //                             async: false,
            //                             success: function (resp) {
            //                                 console.info(JSON.stringify(resp));
            //                                 if (resp.retCode=="0"){
            //                                     json = resp.data;
            //                                     mgrId = json.mgrId;
            //                                     var stationIds  = json.stationIds;
            //                                     var msg = '所选中区域共有'+json.stationCount+'个基站';
            //                                     layer.closeAll();
            //                                     layer.open({
            //                                         title:"提示"
            //                                         ,type: 1
            //                                         ,offset: 'auto'
            //                                         ,id: 'layerDemo2' //防止重复弹出
            //                                         ,content: `<div style="padding: 20px 80px;"><span>${msg}</span></div>`
            //                                         ,btn: ['确定','取消']
            //                                         ,btnAlign: 'c' //按钮居中
            //                                         ,shade: 0 //不显示遮罩
            //                                         ,yes: function(){
            //                                             let jsonParams = {
            //                                                 'mgrId': mgrId,
            //                                                 'range': JSON.stringify(latitudeAndLongitudeValueArr),
            //                                                 'stationIds':stationIds
            //                                             };
            //                                             $.ajax({
            //                                                 contentType: "application/json;charset=UTF-8",
            //                                                 type: 'post',
            //                                                 url: '/sendRange/updateRange',
            //                                                 data: JSON.stringify(jsonParams),
            //                                                 dataType: 'json',
            //                                                 async: false,
            //                                                 success: function (resp) {
            //                                                     if (resp.retCode==="0"){
            //                                                         layer.open({
            //                                                             title: "提示"
            //                                                             , type: 1
            //                                                             , offset: 'auto'
            //                                                             , id: 'layerDemo3' //防止重复弹出
            //                                                             , content: `<div style="padding: 20px 80px;"><span>${msg}已成功保存</span></div>`
            //                                                             , btn: '确定'
            //                                                             , btnAlign: 'c' //按钮居中
            //                                                             , shade: 0 //不显示遮罩
            //                                                             , yes: function () {
            //                                                                 layer.closeAll();
            //                                                             }
            //                                                         });
            //                                                     }else {
            //                                                         layer.msg(resp.retMsg);
            //                                                     }
            //                                                 }
            //                                             });
            //                                         }
            //                                         ,btn2:function(){
            //                                             layer.closeAll();
            //                                         }
            //                                     });
            //                                 } else {
            //                                     layer.msg("获取基站异常："+resp.retMsg);
            //                                 }
            //                             },
            //                             error: function (resp) {
            //                                 console.info(JSON.stringify(resp));
            //                                 layer.msg("获取基站异常"+resp.msg);
            //                             }
            //                         });
            //                     }
            //                     ,btn2: function(){
            //                         layer.closeAll();
            //                     }
            //                 });
            //             }
            //         }
            //         // 添加DOM元素到地图中
            //         map.getContainer().appendChild(div);
            //         // 将DOM元素返回
            //         return div;
            //     }
            //     // 创建控件
            //     var myZoomCtrl = new ZoomControl();
            //     // 添加到地图当中
            //     map.addControl(myZoomCtrl);
            //
            //     /*创建清除按钮*/
            //     function clearControl(){
            //         // 默认停靠位置和偏移量
            //         this.defaultAnchor = BMAP_ANCHOR_TOP_RIGHT;
            //         this.defaultOffset = new BMap.Size(60, 80); // 距离左上角位置
            //     }
            //     clearControl.prototype = new BMap.Control();
            //     clearControl.prototype.initialize = function(map){
            //         var div = document.createElement("div");
            //         div.appendChild(document.createTextNode("清除"));
            //         div.style.cursor = "pointer";
            //         div.style.border = "1px solid gray";
            //         div.style.backgroundColor = "white";
            //         div.style.width = "55px";
            //         div.style.height = "45px";
            //         div.style.textAlign='center';
            //         div.style.backgroundColor='#2e84b5';
            //         div.style.color='#ededed';
            //         div.style.lineHeight='45px';
            //         div.style.textAlign='center';
            //         div.style.borderRadius='10px';
            //         div.onclick = function(e){
            //             clearAll();
            //         }
            //         map.getContainer().appendChild(div);
            //         return div;
            //     }
            //     var myClearCtrl = new clearControl();
            //     map.addControl(myClearCtrl);
            //
            //     var overlaycomplete = function(e){
            //         e.overlay.enableEditing();
            //         //圆
            //         if (e.drawingMode === BMAP_DRAWING_CIRCLE) {
            //             circleOverlays.push(e.overlay);
            //             console.info(e.overlay.getCenter().lng+","+e.overlay.getCenter().lat+"+"+e.overlay.getRadius());
            //         }
            //         //矩形
            //         if(e.drawingMode === BMAP_DRAWING_RECTANGLE){
            //             rectangleOverlays.push(e.overlay);
            //
            //         }
            //         //多边形
            //         if ( e.drawingMode === BMAP_DRAWING_POLYGON ) {
            //             rectangleOverlays.push(e.overlay);
            //         }
            //     };
            //     var styleOptions = {
            //         strokeColor:"blue",    //边线颜色。
            //         fillColor:"blue",      //填充颜色。当参数为空时，圆形将没有填充效果。
            //         strokeWeight: 3,       //边线的宽度，以像素为单位。
            //         strokeOpacity: 0.8,	   //边线透明度，取值范围0 - 1。
            //         fillOpacity: 0.6,      //填充的透明度，取值范围0 - 1。
            //         strokeStyle: 'solid' //边线的样式，solid或dashed。
            //     }
            //     //实例化鼠标绘制工具
            //     var drawingManager = new BMapLib.DrawingManager(map, {
            //         isOpen: false, //是否开启绘制模式
            //         enableDrawingTool: true, //是否显示工具栏
            //         drawingToolOptions: {
            //             anchor: BMAP_ANCHOR_TOP_RIGHT, //位置
            //             offset: new BMap.Size(120, 80), //偏离值
            //             drawingModes : [
            //                 BMAP_DRAWING_CIRCLE,
            //                 BMAP_DRAWING_POLYGON,
            //                 BMAP_DRAWING_RECTANGLE
            //             ]
            //         },
            //         circleOptions: styleOptions, //圆的样式
            //         polygonOptions: styleOptions, //多边形的样式
            //         rectangleOptions: styleOptions //矩形的样式
            //     });
            //     //添加鼠标绘制工具监听事件，用于获取绘制结果
            //     drawingManager.addEventListener('overlaycomplete', overlaycomplete);
            //     //drawingManager.setTop('true');
            //     function clearAll() {
            //         for(var i = 0; i < circleOverlays.length; i++){
            //             map.removeOverlay(circleOverlays[i]);
            //         }
            //         circleOverlays.length = 0 ;
            //         for(var i = 0; i < rectangleOverlays.length; i++){
            //             map.removeOverlay(rectangleOverlays[i]);
            //         }
            //         latitudeAndLongitudeValueArr.length = 0;
            //         rectangleOverlays.length = 0 ;
            //     }
            // };

            function init() {
                let jsonParams ={"mgrId": mgrId} ;
                var url = '/sendRange/queryRange';
                $.ajax({
                    contentType:"application/json;charset=UTF-8",
                    type: 'post',
                    url: url,
                    data:JSON.stringify(jsonParams),
                    dataType:'json',
                    async: false,
                    success: function (data) {
                        if (data.retCode==="0"){
                            console.info("===="+JSON.stringify(data));
                            var color = colorArray[1];
                            var range = data.data.rangeValue;
                            for (let m=0;m<range.length;m++){
                                var extent = range[m].split('+');
                                if (extent.length===2){
                                    var circle = new BMap.Circle(new BMap.Point(extent[0].split(',')[0], extent[0].split(',')[1]),extent[1],{strokeColor:color, strokeWeight:4, fillColor:color,fillOpacity:0.3});
                                    map.addOverlay(circle);
                                    circle.enableEditing();
                                    circleOverlays.push(circle);
                                } else {
                                    var extentPoint = [];
                                    for (let n=0;n<extent.length;n++){
                                        extentPoint.push(new BMap.Point(extent[n].split(',')[0],extent[n].split(',')[1]));
                                    }
                                    var rectangle = new BMap.Polygon(extentPoint,
                                        {strokeColor:color, strokeWeight:4, fillColor:color,fillOpacity:0.3});
                                    console.info(extentPoint);
                                    map.addOverlay(rectangle);
                                    rectangle.enableEditing();
                                    rectangleOverlays.push(rectangle);
                                }
                            }


                        } else {
                            layer.msg("获取项目发送范围异常："+data.retMsg);
                        }
                    },
                    error: function (data) {
                        layer.msg("获取项目发送范围异常："+data.retMsg);
                    }
                });

            }



            //获取多边形经纬度合集
            function getPoints(polygon){
                var latitudeAndLongitudeValue = "";
                var path = polygon.getPath();
                for (i = 0;i<path.length;i++){
                    if (i === path.length-1){
                        latitudeAndLongitudeValue+=path[i].lng+","+path[i].lat;
                        return latitudeAndLongitudeValue;
                    }
                    latitudeAndLongitudeValue+=path[i].lng+","+path[i].lat+"+";
                }
                return latitudeAndLongitudeValue;
            }

            $('#determine').on('click', function () {
                clearLinePointNames();
                var oCks = [];
                oCks = tree.getChecked("demoId1");
                for (let i = 0; i < oCks.length; i++) {
                    var color = colorArray[i%8];
                    var children = oCks[i].children;
                    var oCksNames = [];
                    linePointNames.push(oCksNames);
                    for (let k = 0;k<children.length;k++){
                        var linePointName  = oCks[i].title+"-"+children[k].title;
                        oCksNames.push(linePointName);
                        pointName.push(linePointName);
                        // //添加事件
                        // function addMarker(e,ee,polygon){
                        //     polygon.setFillOpacity(0.3);
                        //     polygon.setFillColor(polygon.getStrokeColor());
                        //     if (pointName.indexOf(linePointNames[i][k]) === -1){
                        //         pointName.push(linePointNames[i][k]);
                        //     }
                        // }
                        // //删除事件
                        // function removeMarker(e,ee,polygon){
                        //     polygon.setFillColor("transparent");
                        //     if (pointName.indexOf(linePointNames[i][k]) === -1){
                        //     } else {
                        //         pointName.splice(pointName.indexOf(linePointNames[i][k]),1);
                        //     }
                        // }
                        var points = [];
                        var pointItude = [];
                        pointItude = children[k].field.split('+');
                        for (let j=0;j<pointItude.length;j++){
                            var itude=[];
                            itude=pointItude[j].split(',');
                            points.push( new BMap.Point(itude[0],itude[1]))
                        }
                        var polygon = new BMap.Polygon(points,
                            {
                                strokeColor : color,
                                fillColor : color,
                                fillOpacity : 0.3,
                                strokeWeight : 4,
                                strokeOpacity : 1
                            }); //创建多边形

                        //创建右键菜单
                        // var menu=new BMap.ContextMenu();
                        //
                        // menu.addItem(new BMap.MenuItem("选中当前点位",addMarker.bind(polygon)));
                        // menu.addItem(new BMap.MenuItem("删除当前点位",removeMarker.bind(polygon)));
                        // polygon.addContextMenu(menu);
                        map.addOverlay(polygon);
                        pointsOverlays.push(polygon);
                        //创建点位标注
                        var opts = {
                            position : points[0],    // 指定文本标注所在的地理位置
                            offset   : new BMap.Size(0, 0)    //设置文本偏移量
                        };
                        var label = new BMap.Label(linePointName, opts);  // 创建文本标注对象
                        label.setStyle({
                            backgroundColor : color,
                            color : "white",
                            fontSize : "12px",
                            height : "20px",
                            lineHeight : "20px",
                            fontFamily:"微软雅黑",
                            borderRadius:"8px",
                            paddingLeft:"5px",
                            paddingRight:"5px",
                            border:"0"
                        });
                        map.addOverlay(label);
                        pointsOverlays.push(label);
                    }
                }
                console.log(linePointNames);
            });
            $('#clearPoints').on('click', function () {
                $("#inputs-name").val("");
                treeData = test("");
                //重载实例
                tree.reload('demoId1', {
                    elem: '#test12' //默认是点击节点可进行收缩
                    ,data: treeData
                    ,edit:false
                    ,showCheckbox: true  //是否显示复选框
                    ,oncheck: function(obj){
                        console.log(obj.data); //得到当前点击的节点数据
                        console.log(obj.checked); //得到当前节点的展开状态：open、close、normal
                        console.log(obj.data.checked); //得到当前节点元素
                    }
                });
                clearLinePointNames();
            });
            function clearLinePointNames() {
                for(let i = 0; i < pointsOverlays.length; i++){
                    map.removeOverlay(pointsOverlays[i]);
                }
                pointName.length = 0;
                pointsOverlays.length = 0 ;
            }
            
            var options = {
                elem: "#table",//表格id
                id: "modelReload", //id
                url: '/smsBaseStation/find',
                method: 'post',
                where: {
		                        mgrId: mgrId,
		                        cityId:cityId,
		                    },
                request: {
                    pageName: 'page',
                    limitName: 'limit',
                },
                response: {
                    statusName: 'code',
                    statusCode: 0,
                    msgName: 'msg',
                    countName: 'count',
                    dataName: 'data'
                },
                page: true,
                count: "count",
                limit: 10,
                limits: [10, 20, 30, 40, 50],
                layout: ['prev', 'page', 'next'],
                prev: "上一页",
                next: "下一页",
                cols: [[ //表头
                     {field: 'regionId', title: '区域编码'}
                    , {field: 'regionName', title: '区域名称'}
                    , {field: 'stationId', title: '基站编码'}
                    , {field: 'stationName', title: '基站名称'}
                ]]
            };
            table.render(options);
            
            upload.render({
				elem : '#importAdd,#importCover',
				url : '/template2/modifyStation',
				auto : false, //关闭自动上传
				accept : 'file', //普通文件
				exts : 'csv', //只允许上传csv文件 //,multiple: true
				bindAction : '#uploadFile',
				before : function() {
		            var param = {
		            		mgrId: mgrId,
		                    cityId: cityId,
		                    importType:importStationType
		                };
		                //var json = JSON.stringify(param);
					layer.load(); //上传loading
					this.data = param;
				},
				done : function(obj) {
	
					layer.closeAll('loading'); //关闭loading
					if (obj.code == 0) {
						var data = obj.data;
						var num = data.toString().split(",");
						layer.confirm('模板添加成功，并成功导入' + data[0] + '个区域,' + data[1] + '个基站', {
							btn: ['确定'] //按钮
						}, function () {
							location.href="smsTemplateManage2.html";
						});
					}
					if (obj.code > 0) {
						layer.msg(obj.msg);
					}
	
				},
				error : function(index, upload) {
					layer.closeAll('loading'); //关闭loading
					layer.msg("上传过程中出现异常，请重试");
				}
			});
			//获取复制的项目ID
			 $('#copy').on('click',function(){
			 	copyMgrId = $("#mgrId_third").val();
			 	mgrNameId = $("#mgrName1").val();
			 	if((''!=mgrNameId && null!=mgrNameId)&&(''!=copyMgrId && null!=copyMgrId))
			 	{layer.confirm('项目名称与项目简称只需选择一个', {
						btn: ['确定'] //按钮
						}, function () {
                         location.href = "stationImport.html?mgrId="+mgrId+"&cityId="+cityId;
			         });
					}else{		 	
			 	if((''!=mgrNameId && null!=mgrNameId)){			
    					var url = '/util/findMgrByName';
    					var param = {
    						mgrName : mgrNameId
    					};
    					$.ajax({
    						type : 'post',
    						async : false,
    						url : url,
    						data : param,
    						success : function(json) {
    							 data = json.data; 
    							 console.log(data.id);	  						
    						 mgrNameId=data.id;	    		
    						},
    						error : function() {
    							layer.msg('系统异常，请联系管理员处理!');
    						}
    					});
    					copyMgrId=mgrNameId;  
    					console.log(copyMgrId); 					
			 	}
			 	layer.confirm('已复制对应基站', {
						btn: ['确定'] //按钮
					});
			 	}		 	
			 });
			 $('#upload2').on('click', function () {
				copyStation();
			});

            $('#upload3').on('click', function () {
                layer.confirm('修改成功', {
                    btn: ['确定'] //按钮
                }, function () {
                    location.href="smsTemplateManage2.html";
                });;
            });

			//判断是覆盖导入还是追加导入
			$(".importStation").click(function(){
				importStationType = $(this).attr('id');
			});
			$('#upload').on('click', function () {
				var choose = $("span.layui-upload-choose").text();
				if(choose!=null && choose!=''){
					$('#uploadFile').trigger("click");
				}else{
					layer.msg("请先选择要导入的csv文件");
				}
			});
			$(".importType").click(function(){
                 	var importType = $("input[name='importType']:checked").val();
                 	if(importType==1){
                 		$(".copyStation").css("display","none");
                 		$(".import").css("display","");
                 		$("#upload").css("display","");
	                	$("#upload2").css("display","none");
                        $("#allmap").css("display","none");
                        $("#upload3").css("display","none");
                 	}else if(importType==2){
                 		$(".copyStation").css("display","");
                 		$(".import").css("display","none");
                 		$("#upload").css("display","none");
	                	$("#upload2").css("display","");
                        $("#allmap").css("display","none");
                        $("#upload3").css("display","none");
                 	}else if(importType==3){
                        $(".copyStation").css("display","none");
                        $(".import").css("display","none");
                        $("#upload").css("display","none");
                        $("#upload2").css("display","none");
                        $("#upload3").css("display","");
                        //$("#allmap").css("display","");
                        // initialFunc();
                        // //mgrId=getUrlParam("mgrId");
                        // console.info("-----"+mgrId);
                        // //treeData = initTest(mgrId);
                        // init();
                        var url = "../sms5g/editSendRange.html?mgrId="+mgrId+"&cityId="+cityId;
                        layer.open({
                            title: '发送区域管理',
                            type: 2,
                            content: url,
                            area: ['1000px', '550px'],
                            scrollbar: true
                        });

                    }
        	});
        	function copyStation(){
	        	if (isNull(copyMgrId)) {
		          layer.msg("未选择要复制的项目");
		          return false;
		        }
        		layer.confirm('确认模板信息无误吗？是否需要再次查看', {
					btn : [ '不需要', '需要' ] //按钮
				}, function(){
					var url = '/template2/copyStation';
	                    		var params = {
	                    			copyMgrId:copyMgrId,
	                    			mgrId:mgrId,         
	                    		}
	                    		var index = layer.load(1, {shade: [0.1,'#fff'] });
	                    		$.ajax({
	                    			type: 'post',
				                    data: params,
				                    url: url,
				                    async: false,
				                    success: function(obj){
				                    	layer.close(index);
				                    	if(obj.data>0){
				                    		layer.confirm('修改成功，并复制'+obj.data+'个基站', {
							                    btn: ['确定'] //按钮
							                }, function () {
							                    location.href="smsTemplateManage2.html";
							                });
				                    	}else{
				                    		layer.confirm('复制项目失败，如需复制项目，请点击确定留在此页面', {
							                    btn: ['确定','退出'] //按钮
							                }, function () {
							                    layer.close(layer.index);
							                }, function () {
							                    location.href="smsTemplateManage2.html";
							                });
				                    	}
				                    },error: function(){
				                    	layer.close(index);
	                    				layer.msg('系统异常，请联系管理员处理!');
				                    }
	                    		});
				});
        	}
            //身份识别
            $(document).ready(function () {
                $(".copyStation").css("display","none");



                if(!isNull(cityId)){
                	$("#cityId").val(cityId);
                    $("#cityId").attr("disabled", true);
                    var data = selectMgrInfo(cityId);
                    appendMgr(data);

                    form.render();


                }
                if(!isNull(mgrId)){
					var select = "dd[lay-value='"+mgrId+"']";
					$('#mgrId').siblings("div.layui-form-select").find('dl').find(select).click();
					$("#mgrId").attr("disabled", "disabled");
					form.render();
                }

            });

            // 苏州   11淮安   12宿迁   13南京   14连云港   15徐州   16常州   17镇江   18无锡   19南通   20泰州   21 盐城   22 扬州   23
            function getJWByCityId(cityId){
                if(cityId=="11"){
                    return new BMap.Point(120.58,31.30);
                }else if(cityId=="12"){
                    return new BMap.Point(119.02,33.62);
                }else if(cityId=="13"){
                    return new BMap.Point(118.28,33.97);
                }else if(cityId=="14"){
                    return new BMap.Point(118.78,32.04);
                }else if(cityId=="15"){
                    return new BMap.Point(119.22,34.60);
                }else if(cityId=="16"){
                    return new BMap.Point(117.18,34.27);
                }else if(cityId=="17"){
                    return new BMap.Point(119.95,31.78);
                }else if(cityId=="18"){
                    return new BMap.Point(119.45,32.20);
                }else if(cityId=="19"){
                    return new BMap.Point(120.30,31.57);
                }else if(cityId=="20"){
                    return new BMap.Point(120.88,31.98);
                }else if(cityId=="21"){
                    return new BMap.Point(119.92,32.45);
                }else if(cityId=="22"){
                    return new BMap.Point(120.15,33.35);
                }else if(cityId=="23"){
                    return new BMap.Point(119.40,32.40);
                }else{
                    return new BMap.Point(118.875, 32.825);
                }
            }

            //根据城市ID查询项目
            function selectMgrInfo(countyId) {
                var data;
                //var url = '/util/findByCityId?cityId=' + cityId;
                var url = '/util/findByMgrId?countyId=' + countyId;
                $.ajax({
                        type: 'post',
                        async: false,
                        url: url,
                        success: function (json) {
                            data = json.data;
                        }, error: function () {
                            layer.msg('系统异常，请联系管理员处理!');
                        }
                    }
                );
                return data;
            }  //监听项目
            form.on('select(cityId)', function (data) {
                var data = selectMgrInfo(data.value);
                appendMgr(data);
            });

            //动态拼接项目
            function appendMgr(data) {
                if (data.length != null) {
                    var options = '<option value="">请选择</option>';
                    for (var i = 0; i < data.length; i++) {
                        options += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
                    }
                    $('#mgrId').html(options);
                } else {
                    $('#mgrId').html('<option value="">该地市下没有项目</option>');
                }
                form.render();
            }
            //根据城市ID查询区县
            function selectCountyId(cityId) {
                var data;
                var url = '/util/findCountyByCityId?cityId=' + cityId;
                $.ajax({
                        type: 'post',
                        async: false,
                        url: url,
                        success: function (json) {
                            data = json.data;
                        }, error: function () {
                            layer.msg('系统异常，请联系管理员处理!');
                        }
                    }
                );
                return data;
            }
			//监听第三步中的地市、区县、项目
		//监听区县
            form.on('select(cityId_third)', function (data) {
                var data2 = selectCountyId(data.value);
                appendCountyThird(data2);
                var data1 = selectMgrInfo(data.value);
                appendMgrThird(data1);
            });
			
			 //监听项目
            form.on('select(countyId_third)', function (data) {
            	if(data.value==null||data.value==''){
	            		var cityId = $("#cityId_third").val();
	            		var data1 = selectMgrInfo(cityId);
	            		appendMgrThird(data1);
	            	}else{
	            		var data1 = selectMgrInfo(data.value);
	                	appendMgrThird(data1);
	            	}
            });
            //动态拼接区县
            function appendCountyThird(data){
                if (data.length != null) {
                    var options = '<option value="">请先选择地市</option>';
                    for (var i = 0; i < data.length; i++) {
                        options += '<option value="' + data[i].countyId + '">' + data[i].countyName + '</option>';
                    }
                    $('#countyId_third').html(options);
                } else {
                    $('#countyId_third').html('该地市下没有区县');
                }
                form.render();
            }
			
			 //动态拼接项目
            function appendMgrThird(data) {
                if (data.length != null) {
                    var options = '<option value="">请选择</option>';
                    for (var i = 0; i < data.length; i++) {
                        options += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
                    }
                    $('#mgrId_third').html(options);
                } else {
                    $('#mgrId_third').html('<option value="">该区县下没有项目</option>');
                }
                form.render();
            }
        //监听第三步中的地市、区县、项目 end
        
        		
    		$("#mgrName1").autocomplete({
       source : function( request, response ) {
        var key = $("#mgrName1").val();
        var cityId=$("#cityId").val();
        var countyId=$("#countyId").val();
        var url = '/util/selectMgrNameLike';
        var param = {
            cityId : cityId,
            countyId : countyId,
         key : key
        };
                 $.ajax({
         type : 'post',
         async : false,
         url : url,
         data : param,
         success : function(json) {
          var data = json.data;
          source = [];
          for (var i = 0; i < data.length; i++) {
           source[i] = data[i].name;
          }
          console.log(source);
          response( source );
         },
         error : function() {
          layer.msg('系统异常，请联系管理员处理!');
         }
        }
        );
            },
       messages : { //message设置不出现匹配关键字的结果
        noResults : '',
        results : function() {
        }
       }
      });
        });
    </script>

</head>
<body>
<div class="layui-content-body">
    <div class="scroll-box">
        <div class="breadcrumb-box">
                <span class="layui-breadcrumb" lay-separator="|">
                     <a href="javascript:returnIndex2()">首页&nbsp;</a>
                  <a href="smsTemplateManage2.html">短信项目模板配置管理</a>
                  <a href="">区域基站导入&nbsp;</a>
                </span>
        </div>
        <div class="content-box">
            <div class="form-select-box">
                <div class="layui-form layui-form-pane">
                    <div class="layui-upload">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">省份</label>
                            <div class="layui-input-block">
                                <input type="text" name="province" lay-verify="required" value="江苏"
                                       autocomplete="off" class="layui-input" disabled>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">地市</label>
                            <div class="layui-input-block">
                                <select id="cityId" name="cityId" lay-filter="cityId" id="cityId">
                                    <option value="">请选择</option>
                                    <option value="11">苏州</option>
                                    <option value="12">淮安</option>
                                    <option value="13">宿迁</option>
                                    <option value="14">南京</option>
                                    <option value="15">连云港</option>
                                    <option value="16">徐州</option>
                                    <option value="17">常州</option>
                                    <option value="18">镇江</option>
                                    <option value="19">无锡</option>
                                    <option value="20">南通</option>
                                    <option value="21">泰州</option>
                                    <option value="22">盐城</option>
                                    <option value="23">扬州</option>
                                    <option value="25">省级</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item mgrName">
                        <div class="layui-inline">
                            <label class="layui-form-label">项目名称</label>
                            <div class="layui-input-block">
                                <select name="mgrId" lay-filter="mgrId" id="mgrId">
                                    <option value="">请先选择地市</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item importType">
					                    	<label class="layui-form-label" style="width:120px">基站来源</label>
					                        <div class="layui-input-block">
					                        	<input class="radioItem" lay-filter="gis" type="radio" name="importType" title="导入基站" onclick="ChooseRadio(this)" value="1" checked="checked">
					                            <input class="radioItem" lay-filter="gis" type="radio" name="importType" title="复制其他项目基站" onclick="ChooseRadio(this)" value="2">
                                                <input class="radioItem" lay-filter="gis" type="radio" name="importType" title="范围选择" onclick="ChooseRadio(this)" value="3">
					                        </div>
					</div>
                    		<div class="layui-form-item copyStation"  style="display:none;">
								<div class="layui-inline ">
									<label class="layui-form-label">地市</label>
									<div class="layui-input-block" style="width:150px">
										<select name="cityId_third" lay-filter="cityId_third" id="cityId_third">
											<option value="">请选择</option>
											<option value="11">苏州</option>
											<option value="12">淮安</option>
											<option value="13">宿迁</option>
											<option value="14">南京</option>
											<option value="15">连云港</option>
											<option value="16">徐州</option>
											<option value="17">常州</option>
											<option value="18">镇江</option>
											<option value="19">无锡</option>
											<option value="20">南通</option>
											<option value="21">泰州</option>
											<option value="22">盐城</option>
											<option value="23">扬州</option>
											<option value="25">省级</option>
										</select>
									</div>
								</div>
								<div class="layui-inline countyId">
		                            <label class="layui-form-label">区县</label>
		                            <div class="layui-input-block" style="width:150px">
		                                <select name="countyId_third" lay-filter="countyId_third" id="countyId_third">
		                                    <option value="">全部</option>
		                                </select>
		                            </div>
		                        </div>
		                        <div class="layui-inline mgrId">
		                            <label class="layui-form-label">项目名称</label>
		                            <div class="layui-input-block" style="width:150px">
		                                <select name="mgrId_third" lay-filter="mgrId_third" id="mgrId_third">
		                                    <option value="">请选择</option>
		                                </select>
		                            </div>
		                        </div>
		                        	<div class="layui-inline">
                            <label class="layui-form-label">项目简称</label>
                            <div class="layui-input-block" style="width:150px">
                                <input type="text"  name="mgrName1" id="mgrName1" lay-verify="required" placeholder="请输入"
                                            autocomplete="off" class="layui-input" />
                            </div>
                        </div>
		                        <div class="layui-inline">
		                            <div class="layui-block">
				                            <button class="layui-btn layui-btn-normal" id="copy">复制</button>
				                            <label id="copyMgrId" style="visibility:hidden;">123</label>
				                	</div>
		                        </div>
							</div>
                            <!--<div id="allmap" style="display: none"></div>-->
                            <div class="layui-form-item import">
        						<label class="layui-form-label" style="width: 120px;">区域基站导入</label>

                                <div class="layui-inline">
                                    	<button type="button" class="layui-btn importStation" id="importCover"><i class="layui-icon"></i>覆盖导入</button>
                                </div>
                                <div class="layui-inline">
                                    	<button type="button" class="layui-btn importStation" id="importAdd"><i class="layui-icon"></i>追加导入</button>
                                </div>
                                <br class="layui-form-item"> <span><a
									href="/smsBaseStation/apidownload"><u>基站导入帮助手册</u></a></span></br> <span><a
									href="/smsBaseStation/modeldownload"><u>基站导入模板下载</u></a></span>
        					</div>
        					<div class="layui-form-item">
								<button class="layui-btn" id="upload">完成</button>
							</div>
							<div class="layui-form-item">
								<button class="layui-btn" id="upload2" style="display:none;">完成</button>
							</div>
                            <div class="layui-form-item">
                                <button class="layui-btn" id="upload3" style="display:none;">完成</button>
                            </div>

							<div class="layui-form-item" style="display:none;">
								<button class="layui-btn" id="uploadFile">上传</button>
							</div>
                        </div>
                    </div>
                </div>
                <div>
                    <h4 class="tips-h4"><i class="iconfont icon-xinxi"></i>提示：基站信息以呈批文件为准！支持重新导入
                    </h4>
                </div>
                 <div class="layui-table">
		                	<table id="table" lay-filter="tableElement"></table>
                 </div>
            </div>
        </div>
    </div>
</div>

</body>
</html>